package com.fourth.controller.api;

import com.fourth.service.MessageService;
import com.fourth.vo.EmpConditionVO;
import com.github.pagehelper.PageInfo;
import com.ljx.entity.Message;
import com.ljx.entity.MsgType;
import com.ljx.entity.Role;
import com.ljx.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Mr.ma
 * @since 2023/2/28 9:11
 **/
@RestController
@RequestMapping("/emp/message")
@Api("公告操作接口")
public class ApiMessageController {
    @Resource
    private MessageService messageService;

    @RequestMapping("getMessage")
    @ApiOperation("查询公告信息，含分页以及条件查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "页码", dataType = "int" , defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量", dataType = "int" , defaultValue = "5"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "String"),
    })
    public Result<PageInfo<Message>> selectAll(@RequestParam(defaultValue = "1") Integer currentPage,
                                               @RequestParam(defaultValue = "5")Integer pageSize,
                                               String startTime, String endTime){
        PageInfo<Message> messages = messageService.selectAll(currentPage,pageSize,startTime,endTime);
        return new Result<>(2000,"查询成功",messages);
    }

    @RequestMapping("sendMessage")
    @ApiOperation("插入公告信息")
    @ApiImplicitParam(name = "message", value = "公告信息", dataType = "Message")
    public Result insertEmp(@RequestBody Message message){
        int row = messageService.insert(message);
        if (row > 0){
            return new Result(2000,"插入成功",null);
        }
        return new Result(5000,"插入失败",null);
    }

    @RequestMapping("updateMessage")
    @ApiOperation("修改公告信息")
    @ApiImplicitParam(name = "message", value = "公告信息", dataType = "Message")
    public Result updateMessage(@RequestBody Message message){
        int row = messageService.updateMessage(message);
        if (row > 0){
            return new Result(2000,"修改成功",null);
        }
        return new Result(5000,"修改失败",null);
    }

    @RequestMapping("deleteMessageById/{id}")
    @ApiOperation("删除公告信息")
    @ApiImplicitParam(name = "id", value = "公告编号", dataType = "String")
    public Result deleteById(@PathVariable String id){
        int row = messageService.deleteById(id);
        if (row > 0){
            return new Result(2000,"删除成功",null);
        }
        return new Result(5000,"删除失败",null);
    }

    @RequestMapping("selectTypeAll")
    @ApiOperation("获取所有类型信息")
    public Result<List<MsgType>> selectTypeAll(){
        List<MsgType> msgTypes = messageService.selectTypeAll();
        return new Result<>(2000,"查询成功",msgTypes);
    }
}
